apiVersion: monitoring.coreos.com/v1
kind: ThanosRuler
metadata:
  labels:
    thanos-ruler: kubesphere
  name: kubesphere
  namespace: kubesphere-monitoring-system
spec:
{% if monitoring.affinity is defined and monitoring.affinity is not none %}
  affinity:
    {{  monitoring.affinity | to_nice_yaml(indent=2) | indent(4) }}
{% elif affinity is defined and affinity is not none %}
  affinity:
    {{ affinity | to_nice_yaml(indent=2) | indent(4) }}
{% else %}
  affinity:
    podAntiAffinity:
      preferredDuringSchedulingIgnoredDuringExecution:
      - podAffinityTerm:
          labelSelector:
            matchExpressions:
            - key: thanos-ruler
              operator: In
              values:
              - kubesphere
          namespaces:
          - kubesphere-monitoring-system
          topologyKey: kubernetes.io/hostname
        weight: 100
{% endif %}
{% if monitoring.nodeSelector is defined and monitoring.nodeSelector is not none %}
  nodeSelector:
    {{ monitoring.nodeSelector | to_nice_yaml(indent=2) | indent(4) }}
{% elif nodeSelector is defined and nodeSelector is not none %}
  nodeSelector:
    {{ nodeSelector | to_nice_yaml(indent=2) | indent(4) }}
{% else %}
  nodeSelector:
    kubernetes.io/os: linux
{% endif %}
{% if monitoring.tolerations is defined and monitoring.tolerations is not none %}
  tolerations:
    {{ monitoring.tolerations | to_nice_yaml(indent=2) | indent(4) }}
{% elif tolerations is defined and tolerations is not none %}
  tolerations:
    {{ tolerations | to_nice_yaml(indent=2) | indent(4) }}
{% else %}
  tolerations: []
{% endif %}
  alertmanagersUrl:
  - dnssrv+http://alertmanager-operated.kubesphere-monitoring-system.svc:9093
  image: {{ thanos_repo }}:{{ thanos_tag }}
  queryEndpoints:
{% if common.monitoring is defined and common.monitoring.endpoint is defined %}
  - {{ common.monitoring.endpoint }}
{% else %}
  - prometheus-operated.kubesphere-monitoring-system.svc:9090
{% endif %}
{% if nodeNum is defined and nodeNum < 3 %}
  replicas: {{ alerting.thanosruler.replicas | default(1) }}
{% else %}
  replicas: {{ alerting.thanosruler.replicas | default(2) }}
{% endif %}
  resources:
    limits:
      cpu: "{{ alerting.thanosruler.resources.limits.cpu | default("1") }}"
      memory: {{ alerting.thanosruler.resources.limits.memory | default("1Gi") }}
    requests:
      cpu: {{ alerting.thanosruler.resources.requests.cpu | default("100m") }}
      memory: {{ alerting.thanosruler.resources.requests.memory | default("100Mi") }}
  ruleNamespaceSelector: {}
  ruleSelector:
    matchLabels:
      role: thanos-alerting-rules
      thanosruler: thanos-ruler